<template>
	<view class="detail">
		<view v-if="detail.name" class="info">
			<view class="info-left">
				<view class="tit">{{detail.name}}</view>
				<view class="desc">
					{{detail.address}} / {{detail.education | codeFilter('STU_EDUCATION')}} /
					{{detail.experience | codeFilter('STU_EXPERIENCE')}}
				</view>
			</view>
			<view class="info-right">
				{{(detail.moneyStart)|price}}-{{detail.moneyEnd|price}}
			</view>
		</view>
		<view v-if="company.companyName" class="company">
			<image class="logo" :src="company.logo" mode=""></image>
			<view class="company-info">
				<view class="company-info-1">
					{{company.companyName}}
				</view>
				<view class="company-info-2">
					{{company.industry | codeFilter('STU_INDUSTRY')}}/{{company.companyCategory |codeFilter('STU_COMPANY_CATEGORY')}}

				</view>
			</view>
		</view>
		<view v-if="!loading" class="content">
			<view class="ms">职位描述</view>
			<view class="it">
				职位类型：{{detail.positionCategory}}
			</view>
			<view class="it">
				所属部门：{{detail.department}}
			</view>
			<view class="it">
				职位亮点：{{detail.highlights}}
			</view>
			<view class="it">
				岗位职责
			</view>
			<view style="margin-top: 10rpx;"><text class="desc">
					{{detail.positionDesc}}
				</text></view>

			<view class="it">
				岗位要求: {{detail.education | codeFilter('STU_EDUCATION')}} /
				{{detail.experience | codeFilter('STU_EXPERIENCE')}}
			</view>
		</view>
		<Loading v-if="loading"></Loading>
		<view @click="save" class="footer-btn">投递简历</view>
	</view>
</template>

<script>
	import {
		getCompanyById,
		getRecruitByCompanyId,
		deliverResume
	} from '@/services/company.js'

	import Config from '@/config/index.js'
	export default {

		filters: {
			price(value) {
				return (value / 1000).toFixed() + 'k'
			}
		},
		data() {
			return {
				company: {},
				loading: false,
				detail: {},

			};
		},
		onLoad({
			id
		}) {
			this.id = id;
			this.getDetail();
		},
		methods: {
			save() {
				uni.chooseImage({
					count: 1,
					success: (e) => {
						var imagePathArr = e.tempFilePaths
						uni.showLoading({
							title: '提交中...'
						})
						console.log(e)
						uni.uploadFile({
							url: Config.uploadUrl,
							filePath: imagePathArr[0],
							name: 'file',
							success: async (res) => {
								if (res.statusCode === 200) {
									console.log(res.data)
									await deliverResume({
										companyRecruitId: this.detail.companyRecruitId,
										path: JSON.parse(res.data).data.path
									})
									uni.hideLoading()
									uni.showToast({
										title: '投递成功',
										icon: 'none'
									})
								} else {
									console.log('fail to upload image:' + res.data)
									uni.showToast({
										title: '服务器出错'
									})
								}
							},
						})
					}
				})
			},
			toDetail(item) {
				uni.setStorageSync('recruit', item)
				uni.navigateTo({
					url: '/'
				})
			},
			async getCompanyDetail() {
				this.loading = true;
				this.company = await getCompanyById({
					companyId: this.detail.companyId
				});
				this.loading = false;
			},
			async getDetail() {
				this.loading = true;
				this.detail = uni.getStorageSync('recruit')
				this.loading = false;
				this.getCompanyDetail()

			},

		}
	};
</script>

<style scoped lang="scss">
	.detail {
		background-color: #f8f8f8;
		min-height: 100vh;

		.company {
			display: flex;
			background-color: #fff;
			padding: 0rpx 30rpx 50rpx;

			.logo {
				width: 80rpx;
				height: 80rpx;
				margin-right: 20rpx;
			}

			.company-info-1 {
				font-size: 34rpx;
			}

			.company-info-2 {
				color: #8a8a8a;
				margin-top: 10rpx;
				font-size: 26rpx;
			}
		}

		.info {
			background-color: #fff;
			padding: 10rpx 30rpx 50rpx;
			display: flex;

			.info-left {
				flex: 1;

				.tit {
					font-size: 42rpx;
					font-weight: bold;
				}

				.desc {
					margin-top: 20rpx;
					font-size: 30rpx;
					color: #8c8c8c;
				}
			}

			.info-right {
				font-size: 35rpx;
				color: #dd524d;

				height: 100rpx;
				width: 100rpx;
			}
		}

		.see {
			padding: 20rpx;
			font-size: 28rpx;
			color: #717070;

			text {
				color: #515151;
				margin-left: 10rpx;
			}
		}
	}

	.content {
		margin-top: 20rpx;
		background-color: #fff;
		padding: 40rpx 30rpx;
		// padding-bottom: 60rpx;
		font-size: 30rpx;

		.ms {
			font-size: 38rpx;
			font-weight: bold;
			padding-bottom: 30rpx;
		}

		.it {
			margin-top: 20rpx;
		}

		.desc {
			margin-top: 20rpx;
			line-height: 1.5;
		}

	}

	.list {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 30rpx 30rpx;
		border-top: 1rpx spild #8a8a8a;
		border-radius: 10rpx;
		height: 110rpx;

		image {
			height: 32rpx;
			width: 32rpx;
			margin-right: 20rpx;
		}

		.list-left {
			.name {
				font-size: 34rpx;
			}

			.tag {
				font-size: 28rpx;
				margin-top: 16rpx;
				color: #8a8a8a;
			}
		}

		.list-right {
			width: 150rpx;
			color: #8a8a8a;
			text-align: right;
			font-size: 26rpx;


			.price {
				font-size: 34rpx;
				color: #dd524d;
			}

			.time {
				margin-top: 20rpx;
			}
		}
	}

	.curriculumDesc {
		background-color: #fff;
		padding-bottom: 400rpx;
		padding: 30rpx;
	}

	.footer-btn {
		position: fixed;
		bottom: 40rpx;
		left: 0;
		right: 0;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: $uni-color-primary;
		color: #fff;
		border-radius: 10rpx;
		height: 80rpx;
		margin: auto;
		width: 690rpx;
	}
</style>
